﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace App.Validate
{
    [AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
    public abstract class ValidatorAttribute: Attribute
    {
        public string RuleName { get; set; }
        public string Tag { get; set; }
        public string MessageTemplate { get; private set; }
        public abstract Validator CreateValidator();

        public ValidatorAttribute(string messageTemplate)
        {
            Guard.ArgumentNotNullOrEmpty(messageTemplate, "messageTemplate");
            this.MessageTemplate = messageTemplate;
            this.RuleName = string.Empty;
        }

        public virtual void FormatMessage(PropertyInfo property)
        {
            this.MessageTemplate = this.MessageTemplate.Replace("{PropertyName}", property.Name)
                .Replace("{Tag}", this.Tag);
        }
    }
}
